// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
    const wxContext = cloud.getWXContext()
    const openID=wxContext.OPENID
    const db=cloud.database()
    const classify=event.classify
    const retJudge=event.needHasDone
    if(retJudge==0){
        let toDo = await db.collection('toDo')
        .where({
            _openid:openID,
            classify:classify
        })
        .get();
        return toDo
    }
    else if(retJudge==1){
        let toDo = await db.collection('toDo')
        .where({
            _openid:openID,
            classify:classify,
            done:true
        })
        .get();
        return toDo
    }
    else{
        let toDo = await db.collection('toDo')
        .where({
            _openid:openID,
            classify:classify,
            done:false
        })
        .get();
        return toDo
    }
}